﻿using UnityEngine;
using System.Collections;

public class SoundKillAfterPlay : MonoBehaviour {

	// This script does a one shot play and then kills the sound.
	public bool StartPlaying = false;
	private bool startedPlaying = false;
	float soundLength = 0;
	// Use this for initialization
	void Start () {
		this.soundLength = this.gameObject.audio.clip.length;
	}
	
	// Update is called once per frame
	void Update () {
		if (this.StartPlaying) {
			this.StartPlaying = false;
			this.gameObject.audio.Play();
			this.startedPlaying = true;
		}
		if (this.startedPlaying) {
			soundLength -= Time.deltaTime;
			if (soundLength <= 0.0f) {
				// Sound is done
				this.startedPlaying = false;
				Destroy (this.gameObject);
			}
		}
	}
}
